var isIE = (document.all) ? true : false;
var moveFlag = "read";
var getEvent = function(evt) {
	return evt ? evt : (window.event ? window.event : null);
};
var _x, _y, _cx, _cy;
var oDragObj;
function mouseDown(event) {
	e = getEvent(event);
	var srcElement = e.srcElement || e.target;
	oDragObj = srcElement;
	if (srcElement.tagName == 'DIV' && srcElement.id != "mainDiv"
			&& srcElement.id != "main") {
		var id = oDragObj.id;
		if ((moveFlag == "read" && id.indexOf("read") >= 0)
				|| (moveFlag == "area" && id.indexOf("area") >= 0)
				|| (id == "mapDiv")) {
			_x = parseInt(e.clientX);
			_y = parseInt(e.clientY);
			_cx = parseInt(srcElement.style.left);
			_cy = parseInt(srcElement.style.top);
			document.onmousemove = mouseMove;
		}
		return false;
	}
	return false;
}
function mouseMove(event) {
	e = getEvent(event);
	oDragObj.style.left = parseInt(_cx + e.clientX - _x) + "px";
	oDragObj.style.top = parseInt(_cy + e.clientY - _y) + "px";
	return false;
}
function mouseUp(event) {
	document.onmousemove = null;
	var id = oDragObj.id;
	if (moveFlag == "read" && id.indexOf("read") >= 0) {
		commitRead(id.replace("read", ""), parseInt(parseInt(oDragObj.style.left)/2),
				parseInt(parseInt(oDragObj.style.top)/2));
	} else if (moveFlag == "area" && id.indexOf("area") >= 0) {
		commitArea(id.replace("area", ""), parseInt(parseInt(oDragObj.style.left)/2),
				parseInt(parseInt(oDragObj.style.top)/2));
	}
}
document.onmousedown = mouseDown;
document.onmouseup = mouseUp;

function initDivWidth() {
	if (document.uniqueID) {
		if (parent.hiddenFlag == false) {// 暂时在IE8中有问题
			mapDx = parseInt(parent.document.body.offsetWidth) - 200;
			mapDy = parseInt(parent.document.body.offsetHeight) - 45;
		} else {
			mapDx = parseInt(parent.document.body.offsetWidth) - 22;
			mapDy = parseInt(parent.document.body.offsetHeight) - 45;
		}
	} else {
		if (parent.hiddenFlag == false) {
			mapDx = parseInt(parent.document.body.offsetWidth) - 204;
			mapDy = parseInt(parent.document.body.offsetHeight) - 130;
		} else {
			mapDx = parseInt(parent.document.body.offsetWidth) - 27;
			if (parent.screenFlag == false) {
				mapDy = parseInt(parent.document.body.offsetHeight) - 120;
			} else {
				mapDy = parseInt(parent.document.body.offsetHeight) - 40;
			}
		}
	}
	getId('mainDiv').style.width = mapDx + "px";
	getId('mainDiv').style.height = mapDy + "px";
};
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
};
addLoadEvent(initDivWidth);
window.onresize = function() {
	initDivWidth();
}
